package com.mallcai.bigdata.ladon.dpl.mapper.report;

import com.mallcai.bigdata.ladon.dpl.entity.report.Group;
import com.mallcai.bigdata.ladon.dpl.mapper.report.provider.GroupSqlProvider;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author gst
 * @date 2019-12-30 20:36
 */
@Repository
public interface GroupMapper {

    @InsertProvider(type = GroupSqlProvider.class, method = "insert")
    int insert(Group group);

    @UpdateProvider(type = GroupSqlProvider.class, method = "update")
    int update(Group group);

    @UpdateProvider(type = GroupSqlProvider.class, method = "delete")
    int delete(Group group);

    @SelectProvider(type = GroupSqlProvider.class, method = "findById")
    Group findById(@Param("id") Long id);

    @SelectProvider(type = GroupSqlProvider.class, method = "getByParams")
    List<Group> getByParams(@Param("params") Map<String, Object> params);

    @SelectProvider(type = GroupSqlProvider.class, method = "hasSameName")
    int hasSameName(@Param("parentId") Long parentId, @Param("name") String name, @Param("filterId") Long filterId);

    @SelectProvider(type = GroupSqlProvider.class, method = "getChildrenByPid")
    List<Group> getChildrenByPid(@Param("parentId") Long parentId);

    @SelectProvider(type = GroupSqlProvider.class, method = "getChildrenByPids")
    List<Group> getChildrenByPids(@Param("parentIds") List<Long> parentIds);

    /**
     * 判断是否存在子节点(报表组或报表)
     */
    @SelectProvider(type = GroupSqlProvider.class, method = "hasChildren")
    int hasChildren(@Param("parentId") Long parentId);

    /**
     * 该SQL用于组装报表组树, 请勿乱改~~
     *
     * @return List
     */
    @Select({
            "SELECT id, parent_id, name, icon, level FROM " + GroupSqlProvider.TB_GROUP +
                    " WHERE archive = 0 " +
                    " ORDER BY level DESC, sort_id ASC, parent_id ASC "
    })
    List<Group> getAllSimpleGroup();
}
